﻿function getAbsoluteLeft(el) {
    var o = el;
    oLeft = o.offsetLeft;
    while (o.offsetParent != null) {
        oParent = o.offsetParent;
        oLeft += oParent.offsetLeft;
        o = oParent;
    }
    return oLeft;
}

function getAbsoluteTop(el) {
    var o = el;
    oTop = o.offsetTop;
    while (o.offsetParent != null) {
        oParent = o.offsetParent;
        oTop += oParent.offsetTop;
        o = oParent;
    }
    return oTop;
}

/*tooltip  使用规则  tips.show("输入不合法","txt_xxx",5000,"black",200)*/
var tips = {
    temp: {},
    show: function (msg, id, time, color, width) {
        var target = this._get(id);
        if (!target) { id = 'window'; }

        if (this._get(id + '_tips')) { this.remove(id); }

        msg = msg || 'error';
        color = color || '#ea0000';
        width = width || 300;
        time = time ? parseInt(time) : false;

        if (id == 'window') {
            var y = document.body.clientHeight / 2 + document.body.scrollTop;
            var x = (document.body.clientWidth - width) / 2;
            var textAlign = 'center', fontSize = '15', fontWeight = 'bold';
        } else {
            for (var y = 0, x = 0; target != null; y += target.offsetTop, x += target.offsetLeft, target = target.offsetParent);
            var textAlign = 'left', fontSize = '12', fontWeight = 'normal';
        }

        var tipsDiv = this._create({ display: 'block', position: 'absolute', zIndex: '1001', width: (width - 2) + 'px', left: (x + 1) + 'px', padding: '5px', color: '#ffffff', fontSize: fontSize + 'px', backgroundColor: color, textAlign: textAlign, fontWeight: fontWeight, filter: 'Alpha(Opacity=50)', opacity: '0.7' }, { id: id + '_text', innerHTML: msg, onclick: function () { tips.hidden(id); } });
        document.body.appendChild(tipsDiv);
        tipsDiv.style.top = (y - tipsDiv.offsetHeight - 12) + 'px';
        document.body.appendChild(this._create({ display: 'block', position: 'absolute', zIndex: '1000', width: (width + 10) + 'px', height: (tipsDiv.offsetHeight - 2) + 'px', left: x + 'px', top: (y - tipsDiv.offsetHeight - 11) + 'px', backgroundColor: color, filter: 'Alpha(Opacity=50)', opacity: '0.7' }, { id: id + '_bg' }));
        if (id != 'window') {
            var arrow = this._create({ display: 'block', position: 'absolute', overflow: 'hidden', zIndex: '999', width: '20px', height: '10px', left: (x + 20) + 'px', top: (y - 13) + 'px' }, { id: id + '_arrow' });
            arrow.appendChild(this._create({ display: 'block', overflow: 'hidden', width: '0px', height: '10px', borderTop: '10px solid ' + color, borderRight: '10px solid #fff', borderLeft: '10px solid #fff', filter: 'Alpha(Opacity=70)', opacity: '0.8' }));
            document.body.appendChild(arrow);
        }
        this.temp[id] = id;

        if (time) { setTimeout(function () { tips.hidden(id); }, time) }

        return id;
    },
    hidden: function (id) {
        if (!id) { for (var i in this.temp) { this.hidden(i); } return; }
        var t = this._get(id + '_text'), d = this._get(id + '_bg'), a = this._get(id + '_arrow');
        if (t) { t.parentNode.removeChild(t); }
        if (d) { d.parentNode.removeChild(d); }
        if (a) { a.parentNode.removeChild(a); }
    },
    _create: function (set, attr) {
        var obj = document.createElement('div');
        for (var i in set) { obj.style[i] = set[i]; }
        for (var i in attr) { obj[i] = attr[i]; }
        return obj;
    },
    _get: function (id) {
        return document.getElementById(id);
    }
};

/*
    支持类对象和json对象
    @source 数据来源,target为对象自己本身
    @overwrite:是否重写重复的属性,默认为true
*/
function extendObj(target, source, overwrite) {
    if (overwrite == undefined) {
        overwrite = true;
    }
    for (var p in source) {
        if (target.hasOwnProperty(p)) {
            if (overwrite) {
                target[p] = source[p];
            }
        }
        else {
            target[p] = source[p];
        }
    }
    return target;
}
/*jq ui dialog init*/
function InitDialog(id, height, width, fun) {
    $("#" + id + "").dialog({
        autoOpen: false,
        resizable: true,
        height: height,
        width: width,
        resizable: true,
        overlay: {
            backgroundColor: '#000',
            opacity: 0.5
        },
        buttons: {
            "OK": function () {
                if (fun != undefined) {
                    fun();
                }
                $(this).dialog('close');
            },
            "Close": function () {
                $(this).dialog('close');
            }
        }
    })
}

/*js random*/
var jsRandom = function () {
    this.msg = "";
    this.index = 0;
    this.init = function (arr) {
        if (arr == null || arr.length == 0) {
            this.msg = "the data source is null , please check again!";
            return false;
        }
        return true;
    }

    this.SetRandom = function (num1, num2) {
        var choices = num2 - num1 + 1;
        return Math.floor(Math.random() * choices + num1);
    }

    this.GetAction = function (arr) {
        var bl = this.init(arr);
        if (bl) {
            this.index = this.SetRandom(0, arr.length - 1);
            return arr[this.index];
        }
        return this.msg;
    }
}

/*paging in the client*/
var pagingMgr = function (data, pageSize, renderData, containerid) {
    this._data = data;
    this._pageSize = pageSize;

    this._result = {};
    this._count = 0;

    this.GetResult = function () {
        if (this._data == null || this._data.length == 0) {
            return;
        }
        var _index = 0;

        for (var i = 0, ci; ci = this._data[i]; i++) {
            if (!this._result[_index]) {
                this._result[_index] = [ci];
            }
            else {
                var _len = this._result[_index].length;
                if (_len == this._pageSize) {
                    _index++;
                    this._result[_index] = [ci]
                }
                else {
                    this._result[_index].push(ci);
                }
            }
        }
        this._count = _index;
    }

    this.RenderPaging = function (container) {
        if (this._data == null || this._data.length == 0) {
            return;
        }
        $(container).html("");
        var html = "";
        if (this._data.length >= this._pageSize) {
            html += "<div class='div_FLeft'>Records <span id='" + containerid + "_span_databegin'>" + 1 + "</span> to <span id='" + containerid + "_span_dataend'>" + this._pageSize + "</span> of " + this._data.length + "</div>";
        }
        else {
            html += "<div class='div_FLeft'>Records <span id='" + containerid + "_span_databegin'>" + 1 + "</span> to <span id='" + containerid + "span_dataend'>" + this._data.length + "</span> of " + this._data.length + "</div>";
        }

        html += "<div class='div_FRight div_padding_right'>";

        if (this._count >= 5) {
            html += "<div class='div_FLeft div_margin_left'>";
            html += "<img src='../Images/arrove_left.png' tag='prev_img' /></div>";

            for (var i = 0; i < 5; i++) {
                if (i == 0) {
                    html += "<div class='product_result_num1' index='" + i + "' tag='page'>" + (i + 1) + "</div>";
                }
                else {
                    html += "<div class='product_result_num' index='" + i + "' tag='page'>" + (i + 1) + "</div>";
                }
            }

            html += "<div class='div_FLeft div_margin_left8'>";
            html += "<img src='../Images/arrow_right.png' tag='next_img'/></div>";
        }
        else {
            for (var i = 0; i < this._count + 1; i++) {
                if (i == 0) {
                    html += "<div class='product_result_num1' index='" + i + "' tag='page'>" + (i + 1) + "</div>";
                }
                else {
                    html += "<div class='product_result_num' index='" + i + "' tag='page'>" + (i + 1) + "</div>";
                }
            }
        }
        html += "</div>";

        $(container).append($(html));
        var that = this;
        $(container).find("img[tag=prev_img]").each(function () {
            this.addEventListener("click", function () { that.RegPrevEvent(this); }, false);
        })
        $(container).find("img[tag=next_img]").each(function () {
            this.addEventListener("click", function () { that.RegNextEvent(this); }, false);
        })
        $(container).find("div[tag=page]").each(function () {
            this.addEventListener("click", function () { that.RegPageEvent(this); }, false);
        })

    }

    this.SetResultList = function (index) {
        $("#" + containerid + "_span_databegin").text(parseInt(index) * this._pageSize - (this._pageSize - 1));
        $("#" + containerid + "_span_dataend").text(parseInt($("#" + containerid + "_span_databegin").text()) + (this._pageSize - 1));
        if ($("#" + containerid + "_span_dataend").text() > this._data.length) {
            $("#" + containerid + "_span_dataend").text(this._data.length);
        }
    }

    this.RegPrevEvent = function (obj) {
        $(obj).parent().parent().find("div[tag=page]").each(function () {
            $(this).removeAttr("disabled");
        })

        var pageObj = $(obj).parent().parent().find("div[tag=page][class=product_result_num1]");
        var index = parseInt(pageObj.attr("index"));
        var html = parseInt(pageObj.html());
        //first page
        if (index == "0") {
            return;
        }

        pageObj.attr("class", "product_result_num");

        if (parseInt(index) % 5 == 0) {
            $(obj).parent().parent().find("div[tag=page]").each(function (j) {
                var _h = html - 5 + j;
                var _i = index - 5 + j;
                if (j == 4) {
                    $(this).attr("class", "product_result_num1").html(_h).attr("index", _i);
                }
                else {
                    $(this).attr("class", "product_result_num").html(_h).attr("index", _i);
                }
            })
        } else {
            pageObj.prev().attr("class", "product_result_num1");
        }


        renderData(this._result[parseInt(index) - 1]);

        index = parseInt(index) - 1;
        this.SetResultList(parseInt(index) + 1);

    }

    this.RegNextEvent = function (obj) {

        $(obj).parent().parent().find("div[tag=page]").each(function () {
            $(this).removeAttr("disabled");
        })

        var pageObj = $(obj).parent().parent().find("div[tag=page][class=product_result_num1]");
        var index = parseInt(pageObj.attr("index"));
        var html = parseInt(pageObj.html());
        if (parseInt(index) == this._count) {
            return;
        }
        var that = this;

        pageObj.attr("class", "product_result_num");

        if ((parseInt(index) + 1) % 5 == 0) {
            $(obj).parent().parent().find("div[tag=page]").each(function (j) {
                var _h = html + 1 + j;
                var _i = index + 1 + j;
                if (_i > that._count) {
                    $(this).attr("class", "product_result_num").html("").attr("disabled", "disabled").attr("index", "none");
                    //$(this).remove();
                }
                else {
                    if (j == 0) {
                        $(this).attr("class", "product_result_num1").html(_h).attr("index", _i);
                    }
                    else {
                        $(this).attr("class", "product_result_num").html(_h).attr("index", _i);
                    }
                }
            })
        } else {
            if (pageObj.next().attr("index") == "none") {

            } else {
                pageObj.next().attr("class", "product_result_num1");
            }
        }

        renderData(this._result[parseInt(index) + 1]);

        index = parseInt(index) + 1;
        this.SetResultList(parseInt(index) + 1);
    }

    this.RegPageEvent = function (obj) {
        var obj = $(obj);
        obj.parent().parent().parent().find("div[tag=page]").each(function () {
            if (obj.attr("index") == $(this).attr("index")) {
                $(this).attr("class", "product_result_num1");
            }
            else {
                $(this).attr("class", "product_result_num");
            }
        })
        var that = this;
        var _index = parseInt($(obj).attr("index"));
        renderData(that._result[_index]);

        var index = obj.attr("index");
        this.SetResultList(parseInt(index) + 1);
    }
}

/*LocalStroage的操作*/
var LocalStroageControl = function () {
    this.isLocalStorage = window.localStorage ? true : false;

    this.set = function (key, value) {
        if (this.isLocalStorage) {
            window.localStorage.setItem(key, value);
        }
        else {
            return;
        }
    }

    this.get = function (key) {
        if (this.isLocalStorage) {
            return window.localStorage.getItem(key);
        }
        else {
            return null;
        }
    }

    this.remove = function (key) {
        if (this.isLocalStorage) {
            localStorage.removeItem(key);
        }
        else {
            return;
        }
    }

    this.GetAllKeys = function () {
        var arrKey = new Array();
        for (var i in localStorage) {
            arrKey.push(i);
        }
        return arrKey;
    }

    this.GetAllValues = function () {
        var arrVal = new Array();
        var arrKey = this.GetAllKeys();
        for (var i = 0; i < arrKey.length; i++) {
            arrVal.push(this.get(arrKey[i]));
        }
        return arrVal;
    }

    this.getAllLocalStroage = function () {
        var arrKey = new Array();
        var arrVal = new Array();
        var json = "";
        for (var i in localStorage) {
            arrKey.push(i);
        }
        if (arrKey.length == 0) {
            alert("there are no localStorages in your computer!");
        }
        else {
            for (var i = 0; i < arrKey.length; i++) {
                arrVal.push(this.get(arrKey[i]));
            }
            json = "[";
            for (var i = 0; i < arrKey.length; i++) {
                json += "{";
                json += arrKey[i] + ":" + "'" + arrVal[i] + "'";
                json += "}";
                json += ",";
            }
            json = json.substring(0, json.lastIndexOf(','));
            json += "]";
        }

        return json;
    }
}

/*给String类添加新的方法trim*/
String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/gi, "");
}

/*添加replaceAll方法*/
String.prototype.replaceAll = function (oldVal, newVal) {
    return this.replace(new RegExp(oldVal, "gm"), newVal);
}

/*判断是否为json*/
function isJson(obj) {
    var isjson = typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && !obj.length;
    return isjson;
}

/*为String类添加转换date的方法*/
String.prototype.ToDate = function () {
    return new Date(this.replace(/-/, "/"));
}

/*为Date类重写ToString方法  返回的格式  xxxx-xx-xx*/
Date.prototype.DateToString = function () {
    var year = this.getFullYear()
    var month = parseInt(this.getMonth()) + parseInt("1");
    var day = this.getDate();
    return year + "-" + month + "-" + day;
}

/*取从num1到num2的随机数的方法 不包含num2*/
function SelectFrom(num1, num2) {
    var choices = num2 - num1 + 1;
    return Math.floor(Math.random() * choices + num1);
}

/*判断一个对象是存在于实例中还是存在于原型中，如果存在于实例中则返回true，否则返回false*/
function hasPrototypeProperty(obj, name) {
    if (obj.hasOwnProperty(name) && name in obj) {
        return true;
    }
    else {
        return false;
    }
}

/*superType是父类,subType是子类,继承需要用到此方法*/
function inheritPrototype(subType, superType) {
    var prototype = Object(superType.prototype);
    prototype.constructor = subType;
    subType.prototype = prototype;
}

/*截取字符串*/
function cutStr(str, num) {
    var temp = "";
    if (str == "" || str == undefined) {
        return "";
    }
    if (str.length > num) {
        temp = str.substring(0, num) + "...";
    }
    else {
        temp = str;
    }
    return temp;
}

/*button按下后，不允许按下一次(给一个div层盖住)*/
function setLoading(obj) {
    var loadingControlID = "divLoadingActive";
    var objCurrent = $(obj);
    var height = objCurrent.height();
    var width = objCurrent.width();
    var offset = objCurrent.offset();
    var left = offset.left;
    var top = offset.top;
    if ($("#" + loadingControlID).length <= 0) {
        $("body").append('<div id=' + loadingControlID + ' style="position:absolute;background-color:gray;text-align:center" >处理中...</div>');
    }
    var objLoadingDiv = $("#" + loadingControlID);
    objLoadingDiv.height(height);
    objLoadingDiv.width(width);
    objLoadingDiv.css("left", left);
    objLoadingDiv.css("top", top);
    return $("#" + loadingControlID);
}

/*关于textbox的title处理解决方案*/
function mouseevent(obj) {
    if ($("#divtitle").length <= 0) {
        $("body").append($("<div id='divtitle' style='position:absolute;font-size:12px;width:150px;table-layout:fixed; word-break: break-all; overflow:hidden;'></div>"));
    }
    $(obj).mousemove(function (e) {
        var posx = e.pageX;
        var posy = e.pageY;
        $("#divtitle").css("display", "block");
        $("#divtitle").css("border", "1px solid gray");
        $("#divtitle").css("background-color", "white");
        $("#divtitle").css("top", posy + 20);
        $("#divtitle").css("left", posx + 20);
        if ($(obj).val() == "") {
            $("#divtitle").css("display", "none");
        }
        $("#divtitle").html($(obj).val());
    })
    $(obj).mouseout(function (e) {
        $("#divtitle").css("display", "none");
    })
}

/*去除textbox边框*/
function verview_reinput(textboxs) {
    $(textboxs).each(function (i) {
        var cor = $(this).parents("td").eq(0).css("background-color");
        $(this).removeAttr("disabled").prop("readonly", "readonly").css({ "background-color": cor, "border-width": "0 0", "color": "#000000", "cursor": "default" });
    });
}

/*比较时间大小,格式xxxx-xx-xx   0为相等，1为大于，-1为小于*/
function comparetime(time1, time2) {
    var date1 = time1.replace(/-/g, "/");
    var date2 = time2.replace(/-/g, "/");
    var d1 = new Date(date1);
    var d2 = new Date(date2);

    if (Date.parse(d1) - Date.parse(d2) == 0) {
        return "0";
    }
    if (Date.parse(d1) - Date.parse(d2) < 0) {
        return "-1";
    }
    if (Date.parse(d1) - Date.parse(d2) > 0) {
        return "1";
    }
}

/*当前输入时间转换成星期几格式  2012-8-25*/
function toDay(str) {
    var arr = "日一二三四五六".split("");
    vYear = str.split('-')[0];
    vMonth = str.split('-')[1];
    vDay = str.split('-')[2];
    return "星期" + arr[new Date(vYear, vMonth - 1, vDay).getDay()];
}

/*去除数组里的重复项 返回新的数组*/
Array.prototype.unique = function () {
    var temp = new Array();
    this.sort();
    for (i = 0; i < this.length; i++) {
        if (this[i] == this[i + 1]) {
            continue;
        }
        temp[temp.length] = this[i];
    }
    return temp;
}

/*判断某项在数组里是否存在  true代表存在 false代表不存在*/
Array.prototype.isExist = function (val) {
    var bl = false;
    for (var i = 0; i < this.length; i++) {
        if (val == this[i]) {
            bl = true;
        }
    }
    return bl;
}

/*js删除数组里的index项  索引从0开始  返回新的数组*/
Array.prototype.delByIndex = function (index) {
    if (index < 0) {
        return this;
    }
    else {
        return this.slice(0, index).concat(this.slice(index + 1, this.length));
    }
}

/*字符串过长的换行问题---主要用于div的tooltip*/
function cutString(str, strcutlength) {
    var result = "";
    var num = 0;
    var count = str.length;
    for (i = 0; i < count; i++) {
        if (str.charCodeAt(i) > 255) {
            num = num + 2;
        }
        else {
            num = num + 1;
        }
        if (num > strcutlength) {
            result = result + "<br/>" + String.fromCharCode(str.charCodeAt(i));
            num = num - strcutlength;
        }
        else {
            result = result + String.fromCharCode(str.charCodeAt(i));
        }
    }
    return result;
};

/*时间转换*/
function ChangeDate(val) {
    var res = "";
    if (val == null || val == "null") {
        res = "";
    } else {
        var d = new Date(val);
        d = d.toLocaleDateString();
        d = d.replace('年', '-').replace('月', '-').replace('日', '');
        var arr = d.split('-');
        var yy = arr[0];
        var mm = arr[1];
        var dd = arr[2];
        if (parseInt(mm) < 10) {
            mm = "0" + mm;
        }
        if (parseInt(dd) < 10) {
            dd = "0" + dd;
        }
        res = yy + "-" + mm + "-" + dd;
    }
    return res;
}

/*时间转换 格式 2012-9-9 00:00:00*/
function ChangeDateByDate(val) {
    if (val == "") {
        return;
    } else {
        return val.split(' ')[0];
    }
}

/*ajax方法*/
function SendAjax(type, url, data, datatype, callback) {
    $.ajax({
        type: reqtype,
        async: true,
        url: requrl,
        dataType: datatype == "" ? "text" : datatype,
        data: reqdata,
        cache: false,
        success: callback,
        error: function (jqXHR, textStatus, errorThrown) {
            alert("HTTP请求错误代码:" + jqXHR.status + ",描述:" + jqXHR.statusText);
        }
    });
}

/*自定义的弹出层,需要引入jq jqui*/
var CusDialog = {
    ConfirmDialog: function (title, content, callback) {
        var html = "<div id='divconfirm' style='display: block; z-index: 1007; outline: 0px none; height: auto; width: 400px; top: 107.5px; left: 519px;' class='ui-dialog ui-widget ui-widget-content ui-corner-all confirm-warn ui-draggable' tabindex='-1' role='dialog' aria-labelledby='ui-dialog-title-1'><div class='ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix'><span class='ui-dialog-title' id='ui-dialog-title-1'>" + title + "&nbsp;</span><a href='#' class='ui-dialog-titlebar-close ui-corner-all' role='button'><span id='divdialogClose' class='ui-icon ui-icon-closethick' onclick='divdialoghide();'>close</span></a></div><div class='ui-dialog-content ui-widget-content' style='width: auto; min-height: 38px; height: auto;' scrolltop='0' scrollleft='0'><div class='dialog-del-status'>" + content + "</div></div><div class='ui-dialog-buttonpane ui-widget-content ui-helper-clearfix'><div class='ui-dialog-buttonset'><button type='button' class='btn-sure' id='divdialogAjaxSend'>确    定</button><button type='button' class='btn-cancel' id='divcancel'>取 消</button></div></div></div>";
        $("body").append($(html));
        $("#divdialogAjaxSend").click(function () {
            if (callback == null) {
                $("#divconfirm").remove();
                return false;
            }
            callback();
            $("#divconfirm").remove();
        })

        $("#divdialogClose").click(function () {
            $("#divconfirm").remove();
        })

        $("#divcancel").click(function () {
            $("#divconfirm").remove();
        })
    },
    ShowDialogWithNoButton: function (div, title, width, height) {
        $(div).dialog({
            title: title,
            autoOpen: false,
            bgiframe: true,
            resizable: false,
            width: width,
            height: height,
            modal: false,
            overlay: {
                backgroundColor: '#000',
                opacity: 0.5
            }
        });
    },
    ShowDialog: function (div, title, width, height, callback) {
        $(div).dialog({
            title: title,
            autoOpen: false,
            bgiframe: true,
            resizable: false,
            width: width,
            height: height,
            modal: false,
            overlay: {
                backgroundColor: '#000',
                opacity: 0.5
            },
            buttons: {
                "Ok": callback,
                "Cancel": function () {
                    $(this).dialog("close");
                }
            }
        });
    },
}

function confirminfo(val) {
    if (window.confirm(val)) {
        return true;
    }
    return false;
}

function strToJson(str) {
    if (str == "") {
        return null;
    }
    var json = eval('(' + str + ')');
    return json;
}

/*参数说明:
    option:{
        method:"",
        url:"",
        data:"",
        isEncodeURI:"",
        callback:"",
        isAsyn:"",
        resendCount:""
    }
*/
var ajax = function (option) {
    this.xmlHttp = null;

    this.resType = option.method;
    this.url = option.url;
    this.parm = option.data;
    this.isEncodeURI = option.isEncodeURI;
    this.callback = option.callback;
    this.isAsyn = option.isAsyn;
    this.resendCount = option.resendCount;

    this.CreateXmlHttpRequest = function () {
        if (window.ActiveXObject) {
            this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else if (window.XMLHttpRequest) {
            this.xmlHttp = new XMLHttpRequest();
        }
    }

    //{ a:"a",b:"b"}  convert to "a="+a+"&b="+b;
    this.CreateQueryString = function () {
        if (this.parm == null) {
            return "";
        }
        var pro_Arr = new Array();
        var val_Arr = new Array();
        for (var i in this.parm) {
            pro_Arr.push(i);
        }
        for (var i = 0; i < pro_Arr.length; i++) {
            val_Arr.push(this.parm[pro_Arr[i]]);
        }

        var result = "";
        for (var i = 0; i < pro_Arr.length; i++) {
            result += pro_Arr[i] + "=" + val_Arr[i] + "&";
        }
        result = result.substring(0, result.lastIndexOf('&'));

        if (this.isEncodeURI) {
            result = encodeURI(encodeURI(result));
        }
        result = result + "&ran=" + Math.random();
        return result;
    }

    var that = this;
    this.DoRequest = function () {
        this.CreateCoverDiv();
        if (this.xmlHttp == null) {
            this.CreateXmlHttpRequest();
        }
        if (this.resType.toLowerCase() == "get") {
            var _p = this.CreateQueryString(this.parm, false);
            this.xmlHttp.open("GET", this.url + "?" + _p, this.isAsyn);
            this.xmlHttp.onreadystatechange = this.HandleStateChange;
            this.xmlHttp.send(null);
        }
        if (this.resType.toLowerCase() == "post") {
            var _p = this.CreateQueryString(this.parm, false);
            this.xmlHttp.open("POST", this.url, this.isAsyn);
            this.xmlHttp.onreadystatechange = this.HandleStateChange;
            this.xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            this.xmlHttp.send(_p);
        }
    }

    this.HandleStateChange = function () {
        //alert(that.xmlHttp.readyState);
        if (that.xmlHttp.readyState == 4) {
            if (that.xmlHttp.status == 200) {
                that.RemoveCoverDiv();
                that.callback(that.xmlHttp.responseText);
            }
            else {
                that.ErrorCallBack(that.resendCount, 1500);
            }
        } else {
            //alert("服务器未准备就绪!");
            //that.DoRequest();
        }
    }

    this.count = 0;
    this.ErrorCallBack = function (count, time) {
        if (that.count >= count) {
            that.RemoveCoverDiv();
        } else {
            window.setTimeout(function () { that.DoRequest(); }, time);
        }
        that.count++;
    }

    /* create discoverDiv and remove it */
    this.CreateCoverDiv = function () {
        var _coverDiv = document.createElement("div");
        var sWidth = document.documentElement.clientWidth;
        var sHeight = document.documentElement.clientHeight;
        _coverDiv.setAttribute("tag", "cover");
        _coverDiv.setAttribute('id', '_coverDiv');
        _coverDiv.style.position = "absolute";
        _coverDiv.style.top = "0";
        _coverDiv.style.background = "#777";
        _coverDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
        _coverDiv.style.opacity = "0.6";
        _coverDiv.style.left = "0";
        _coverDiv.style.width = sWidth + "px";
        _coverDiv.style.height = sHeight + "px";
        _coverDiv.style.zIndex = "10000";
        _coverDiv.style.textAlign = "center";
        _coverDiv.style.verticalAlign = "middle";
        _coverDiv.style.lineHeight = "700px";
        _coverDiv.innerHTML = "<img src='/Resource/Image/bx_loader.gif'></img>";
        document.body.appendChild(_coverDiv);
    }
    this.RemoveCoverDiv = function () {
        $("div[tag=cover]").each(function () {
            $(this).remove();
        })
    }

    this.DoRequest();
    /* create discoverDiv and remove it */
}

/*获取URL后面的参数值*/
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
};
